using System.Data.Entity.ModelConfiguration;
using System.ComponentModel.DataAnnotations;

namespace DemoApp.DataAccess 
{
  public partial class SubjectEntityConfiguration 
    : EntityTypeConfiguration<Subject>
  {
    public SubjectEntityConfiguration()
    {
      HasEntitySetName(@"Subjects");
      Map(map => {
        map.ToTable(@"Subjects");
      });
      HasKey(e => new { e.SubjectId });
 

      Property(e => e.SubjectId) 
        .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

      Property(e => e.Url) 
        .HasMaxLength(260);

      Property(e => e.Title) 
        .HasMaxLength(260);

      Property(e => e.Description);

      Property(e => e.ImageUrl) 
        .HasMaxLength(260);

      Property(e => e.CreateDate);

      Property(e => e.ModifyDate);

      Property(e => e.IsDisabled);
 

      HasRequired(e => e.Creator) 
        .WithMany(e => e.CreatedSubjects)
        .HasForeignKey(e => new { e.CreatorId })
        .WillCascadeOnDelete(false);

      HasMany(e => e.Editors)
        .WithMany(e => e.EditedSubjects);

      HasOptional(e => e.ParentSubject) 
        .WithMany(e => e.SubSubjects)
        .HasForeignKey(e => new { e.ParentSubjectId })
        .WillCascadeOnDelete(false);
    }
  }
}
